package com.cyl.manager.pms.service;

import java.time.LocalDateTime;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyl.manager.pms.domain.entity.PmsBrandAttention;
import com.cyl.manager.pms.domain.query.PmsBrandAttentionQuery;
import com.cyl.manager.pms.mapper.PmsBrandAttentionMapper;
import com.cyl.manager.ums.domain.entity.UserInfo;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.framework.config.LocalDataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;


/**
 * 品牌关注Service业务层处理
 *
 *
 * @author zcc
 */
@Service
public class PmsBrandAttentionService {
    @Autowired
    private PmsBrandAttentionMapper pmsBrandAttentionMapper;

    /**
     * 查询品牌关注
     *
     * @param id 品牌关注主键
     * @return 品牌关注
     */
    public PmsBrandAttention selectById(Integer id) {
        return pmsBrandAttentionMapper.selectById(id);
    }

    /**
     * 查询品牌关注列表
     *
     * @param query 查询条件
     * @param page 分页条件
     * @return 品牌关注
     */
    public List<PmsBrandAttention> selectList(PmsBrandAttentionQuery query, Pageable page) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        QueryWrapper<PmsBrandAttention> qw = new QueryWrapper<>();
        Integer userid = query.getUserId();
        if (userid != null) {
            qw.eq("userId", userid);
        }
        Integer brandId = query.getBrandId();
        if (brandId != null) {
            qw.eq("brandId", brandId);
        }
        return pmsBrandAttentionMapper.selectList(qw);
    }

    /**
     * 新增品牌关注
     *
     * @param pmsBrandAttention 品牌关注
     * @return 结果
     */
    public int insert(PmsBrandAttention pmsBrandAttention) {
        UserInfo member = (UserInfo) LocalDataUtil.getVar(Constants.MEMBER_INFO);
        pmsBrandAttention.setCreateTime(LocalDateTime.now());
        pmsBrandAttention.setUserId(member.getId());
        pmsBrandAttention.setFollower("1");
        return pmsBrandAttentionMapper.insert(pmsBrandAttention);
    }

    /**
     * 修改品牌关注
     *
     * @param pmsBrandAttention 品牌关注
     * @return 结果
     */
    public int update(PmsBrandAttention pmsBrandAttention) {
        return pmsBrandAttentionMapper.updateById(pmsBrandAttention);
    }

    /**
     * 批量删除品牌关注
     *
     * @param ids 需要删除的品牌关注主键
     * @return 结果
     */
    public int deleteByIds(Long[] ids) {
        return pmsBrandAttentionMapper.updateDelFlagByIds(ids);
    }

    /**
     * 删除品牌关注信息
     *
     * @param id 品牌关注主键
     * @return 结果
     */
    public int deleteById(Long id) {
        Long[] ids = {id};
        return pmsBrandAttentionMapper.updateDelFlagByIds(ids);
    }

    public int removeBrand(Long userId, Long brandId) {
        return pmsBrandAttentionMapper.removeBrand(userId, brandId);
    }
}
